import { getCategory1List, getCategory2List, getCategory3List } from "@/api/product/category";
import { defineStore } from "pinia"; 
import type { CategoryStore } from "./interface";

const useCategoryStore=defineStore("attr",{
  state:():CategoryStore=>{
    return{
      category1Id:undefined,
      category2Id:undefined,
      category3Id:undefined,
      category1List:[],
      category2List:[],
      category3List:[],
    }
  },
  actions:{
    async getCategory1List(){
      this.category1List=await getCategory1List()
    },
    async getCategory2List(category1Id:number){
      
      this.category2List=await getCategory2List(category1Id);
      this.category2Id=undefined;
      this.category3Id=undefined;
      this.category3List=[]
    },
    async getCategory3List(category2Id:number){
    
      this.category3List=await getCategory3List(category2Id)
      this.category3Id=undefined;
    },
    removeList(){
      this.category1Id=undefined;
      this.category2Id=undefined;
      this.category3Id=undefined;
     this.category1List=[];
     this.category2List=[];
     this.category3List=[];
    }
  },
  getters:{}
})


export default useCategoryStore